﻿@using Users.Infrastructure
@model IEnumerable<Users.Models.AppRole>
@{
    ViewBag.Title = "角色";
}
<div class="panel panel-primary">
    <div class="panel panel-heading">角色</div>
    <table class="table table-striped">
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Users</th>
            <th>操作</th>
        </tr>
        @if (Model.Count() == 0)
        {
            <tr><td colspan="4" class="text-center">暂无角色</td></tr>
        }
        else
        {
            foreach (var role in Model)
            {
                <tr>
                    <td>@role.Id</td>
                    <td>@role.Name</td>
                    <td>
                        @if (role.Users == null || role.Users.Count <= 0)
                        {
                            @:该角色下暂无用户
                        }
                        else
                        {
                            <p>
                                @string.Join(", ", role.Users.Select(x => Html.GetUserName(x.UserId)))
                            </p>
                        }
                    </td>
                    <td>
                        @using (Html.BeginForm("Delete", "Role", new {id = role.Id}))
                        {
                            @Html.ActionLink("编辑", "Edit", new {id = role.Id}, new {@class = "btn btn-primary btn-xs"})
                            <button class="btn btn-danger btn-xs" type="submit">
                                删除
                            </button>
                        }
                    </td>
                </tr>
            }
        }

    </table>
</div>
@Html.ActionLink("创建", "Create", null, new { @class = "btn btn-primary" })
